package com.spark.basecommon.exception;

import com.spark.basecommon.api.ResultCode;
import lombok.Builder;

/**
 * @author fuqiang
 * @Description 自定义业务异常
 * @Date 2020/10/9
 */
public class BusinessException extends RuntimeException {
    /**
     * 是否成功
     */
    @Builder.Default
    private boolean success = false;
    /**
     * 返回码
     */
    private Long code;
    /**
     * 返回信息
     */
    private String msg;

    public BusinessException(String msg){
        super(msg);
        this.code = ResultCode.FAILED.getCode();
        this.msg = msg;
    }

    public BusinessException(String msg , Long code){
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(ResultCode code , Throwable e){
        super(code.getMessage(),e);
        this.code = code.getCode();
        this.msg = e.getMessage();
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
